#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H

#include <QSyntaxHighlighter>
#include <QTextCharFormat>
#include "HRule.h"

//-------------------------------------

class QTextDocument;

//-------------------------------------

class Highlighter : public QSyntaxHighlighter
{
    Q_OBJECT

    QVector< HRule > rules;
    QRegExp commentStartExpression;
    QRegExp commentEndExpression;
    QTextCharFormat commentFormat;

    QVector< HRule > dynamicRules;

public:
    Highlighter(QTextDocument *parent = 0);

    void addRule( QString p, QTextCharFormat f, QString hint = QString() );
    void addRule( HRule & r ) { rules.append(r); }
    QVector< HRule > * getRules() { return &rules; }
    void clear() { rules.clear(); }
    void save( const QString file );
    void load( const QString f );
    QString convertToCStr( const QString & pattern );
    void updateHighlighter( QTextDocument * doc );
    bool RuleExists( QString & r );

protected:
    void highlightBlock( const QString & text );

private:
    bool checkRuleExist( QString & hint );
    bool checkDynamicRuleExist( QString & hint );
    void addDynamicRule( QString p, QTextCharFormat f, QString hint = QString() );
    void addDynamicRule( HRule & r ) { dynamicRules.append(r); }
    void addDynamicRule( QString r );
    void highlightByRules( QVector< HRule > & rulesList, const QString & text );
    void fillReservedKeyList();
    QString makePattern( const QString & str );

signals:
    
public slots:
    void sltAddRule( QString r ) { addDynamicRule( r ); }
};

#endif // HIGHLIGHTER_H
